Skip to content

fix: reject invalid dynamic filter regexes during config loading#1637

Open
immanuwell wants to merge 1 commit into
prometheus:mainfrom
immanuwell:fix-dynamic-filter-regex-validation
Open

fix: reject invalid dynamic filter regexes during config loading#1637
immanuwell wants to merge 1 commit into
prometheus:mainfrom
immanuwell:fix-dynamic-filter-regex-validation

Conversation

@immanuwell

Copy link
Copy Markdown
Contributor

Bad dynamic filter regexes are accepted during config load, then can panic later when the scrape path hits regexp.MustCompile.

This makes the exporter reject that config earlier, and keeps the collector off the panic path too. Pretty small fix, but useful.

Repro:

  1. Use a dynamic filter with values: ["("]
  2. Start snmp_exporter. Config load is fine on current main
  3. Hit a scrape that evaluates that filter
  4. The exporter panics with missing closing )

With this patch, config loading fails early with invalid dynamic filter value "(".

cc @SuperQ

Comment thread collector/collector.go Outdated
Signed-off-by: immanuwell <pchpr.00@list.ru>
@immanuwell immanuwell force-pushed the fix-dynamic-filter-regex-validation branch from aca2df4 to 6d6c606 Compare July 1, 2026 07:05
@immanuwell immanuwell requested a review from SuperQ July 1, 2026 07:08
@immanuwell

Copy link
Copy Markdown
Contributor Author

@SuperQ addressed your suggestions, PTAL

@SuperQ SuperQ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, minor nit about naming.

Comment thread config/config.go
Comment on lines +252 to +254
func (c *DynamicFilter) Regexps() []*regexp.Regexp {
return c.regexps
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, can we call this Filters for consistency with what it is?

Suggested change
func (c *DynamicFilter) Regexps() []*regexp.Regexp {
return c.regexps
}
func (c *DynamicFilter) Filters() []*regexp.Regexp {
return c.filters
}

Comment thread config/config.go
Oid string `yaml:"oid"`
Targets []string `yaml:"targets,omitempty"`
Values []string `yaml:"values,omitempty"`
regexps []*regexp.Regexp `yaml:"-"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
regexps []*regexp.Regexp `yaml:"-"`
filters []*regexp.Regexp `yaml:"-"`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants